﻿using BookManege.entity;
using System.Security.Cryptography;

namespace BookManege.controller
{
    public partial class manage : Form
    {
        private readonly bookManege bookManege;
        private readonly index index;
        private readonly borrowManege borrowManege;
        private readonly userManege userManege;
        private readonly enterBook enterBook;
        private readonly borrowBook borrowBook;
        private readonly stillBook stillBook;
        private readonly stillbookManage stillbookManage;
        public manage()
        {
            InitializeComponent();
            //左上头像和用户名
            if (Program.user != null)
            {
                linkLabel1.Text = Program.user.NickName;
                pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                pictureBox1.ImageLocation = Program.user.Avatar;
                linkLabel1.Text = Program.user.UserName;
                linkLabel2.Text = Program.user.Authority == 1 ? "管理员" : "普通用户";
                //判断权限显示对应的菜单栏
                treeView1.Nodes.Add(new TreeNode("主页"));
                if (Program.user.Authority == 1)
                {
                    treeView1.Nodes.Add(new TreeNode("图书管理"));
                    treeView1.Nodes.Add(new TreeNode("借阅情况"));
                    treeView1.Nodes.Add(new TreeNode("归还处理"));
                    treeView1.Nodes.Add(new TreeNode("图书录入"));
                    treeView1.Nodes.Add(new TreeNode("用户管理"));
                }
                else
                {
                    treeView1.Nodes.Add(new TreeNode("图书借阅"));
                    treeView1.Nodes.Add(new TreeNode("图书归还"));
                }
            }
            index = new index
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };
            index.Show();
            splitContainer1.Panel2.Controls.Add(index);

            bookManege = new bookManege
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };

            borrowManege = new borrowManege
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };

            userManege = new userManege
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };

            enterBook = new enterBook
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };

            borrowBook = new borrowBook
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };

            stillBook = new stillBook
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };
            stillbookManage = new stillbookManage
            {
                Dock = DockStyle.Fill,
                FormBorderStyle = FormBorderStyle.None,
                TopLevel = false
            };

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            switch (e.Node.Text)
            {
                case "图书管理":
                    splitContainer1.Panel2.Controls.Clear();
                    bookManege.Show();
                    splitContainer1.Panel2.Controls.Add(bookManege);
                    break;
                case "借阅情况":
                    splitContainer1.Panel2.Controls.Clear();
                    borrowManege.Show();
                    splitContainer1.Panel2.Controls.Add(borrowManege);
                    break;
                case "归还处理":
                    splitContainer1.Panel2.Controls.Clear();
                    stillbookManage.Show();
                    splitContainer1.Panel2.Controls.Add(stillbookManage);
                    break;
                case "图书录入":
                    splitContainer1.Panel2.Controls.Clear();
                    enterBook.Show();
                    splitContainer1.Panel2.Controls.Add(enterBook);
                    break;
                case "用户管理":
                    splitContainer1.Panel2.Controls.Clear();
                    userManege.Show();
                    splitContainer1.Panel2.Controls.Add(userManege);
                    break;
                case "图书借阅":
                    splitContainer1.Panel2.Controls.Clear();
                    borrowBook.Show();
                    splitContainer1.Panel2.Controls.Add(borrowBook);
                    break;
                case "图书归还":
                    splitContainer1.Panel2.Controls.Clear();
                    stillBook.Show();
                    splitContainer1.Panel2.Controls.Add(stillBook);
                    break;
                default:
                    splitContainer1.Panel2.Controls.Clear();
                    index.Show();
                    splitContainer1.Panel2.Controls.Add(index);
                    break;
            }

        }
    }
}
